package edu.csumb.itcd.teammario;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;

public class PauseMenu extends JPanel implements Runnable, MouseListener {


    private int selectorPosition;
    private boolean quit;
    private boolean restart;
    private Thread pauseThread;
    
	public PauseMenu()
	{
		this.setBounds(-1, -1, 800, 600);
    	this.setBackground(new Color(0,0,0));
    	selectorPosition = 350;
    	pauseThread = new Thread(this);
    	pauseThread.start();
    	
    	addMouseListener(this);
	}
	
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		
		g.fillRect(0, 0, this.getWidth(), this.getHeight());
    	g.setFont(new Font("Comic Sans MS", Font.PLAIN, 48));    	
		g.setColor(Color.green);
		g.fillRect(250, selectorPosition, 300, 75);
		
		g.setColor(Color.white);
		g.drawString("Pause", 340, 200);
		g.drawString("Continue", 300, 300);
		g.drawString("Restart", 325, 400);
		g.drawString("Quit", 350, 500);
	}
	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		if (quit && Setup.isPaused())
        {
//        	try {
//				lb.readDataBase();
//			} catch (SQLException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
			Setup.setPlay(false);
        } else if (restart && Setup.isPaused())
        {
        	Setup.getGamePanel().reset();
        	Setup.setPause(false);
        } else
        {
        	Setup.setPause(false);
        }
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (true)
		{
			if (Setup.isPaused())
			{		
				if (this.getMousePosition() != null && this.getMousePosition().y < 325)
				{
					selectorPosition = 250;
					quit = false;
					restart = false;
				} else if (this.getMousePosition() != null && this.getMousePosition().y < 425)
				{
					selectorPosition = 350;
					quit = false;
					restart = true;					
				} else if (this.getMousePosition() != null)
				{
					selectorPosition = 445;
					quit = true;
					restart = false;
				}
				
				repaint();
			}
			
			try {
				Thread.sleep(30);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
